home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / fido / AmiGate14.lha / AmiStat.rexx < prev   
OS/2 REXX Batch file  |  1994-09-15  |  5KB  |  178 lines

  1. /************************************************************/
  2. /*            AmiGate accounting generator                  */
  3. /*          $VER: AmiStat.rexx 0.1ß (10.2.94)               */
  4. /*                                                          */
  5. /* This program analyzes the AmiGate logfile and generates  */
  6. /* accounting information.                                  */
  7. /*                                                          */
  8. /* Example: rx AmiStat.rexx 24.12.93 24.02.94               */
  9. /* or just: rx AmiStat.rexx                                 */
  10. /*                                                          */
  11. /* Author: Brian Jacobsen   FidoNet: 2:236/19.73            */
  12. /*                          Email: brj@boble.ping.dk        */
  13. /************************************************************/
  14. signal on syntax
  15. options results
  16. trace off
  17.  
  18. nodes. = 0
  19. received. = 0
  20. sent. = 0
  21. nodecounter = 0
  22. StartDate = ''
  23. StopDate = ''
  24. Complete = 0
  25.  
  26. PARSE ARG argstartdate argstopdate
  27.  
  28. logfile = 'Logs:AmiGateAcc.log'                            /* Logfile to examine */
  29.  
  30. IF argstartdate ~= '' THEN
  31.     DO
  32.         PARSE VAR argstartdate day '.' month '.' year
  33.         day = RIGHT(day,2,'0')
  34.         month = RIGHT(month,2,'0')
  35.         if LENGTH(year) = 2 THEN year = '19' || year
  36.         StartDate = year||month||day
  37.     END
  38.  
  39. IF argstopdate ~= '' THEN
  40.     DO
  41.         PARSE VAR argstopdate day '.' month '.' year
  42.         day = RIGHT(day,2,'0')
  43.         month = RIGHT(month,2,'0')
  44.         if LENGTH(year) = 2 THEN year = '19' || year
  45.         StopDate = year||month||day
  46.     END
  47.  
  48. IF StartDate = '' | StopDate = '' THEN
  49.     Complete = 1
  50.  
  51. IF open('loghandle',logfile,'Read') ~= 1 THEN
  52.     DO
  53.         say 'Open logfile:' logfile 'failed.'
  54.         SIGNAL exit
  55.     END
  56.  
  57. inline = READLN('loghandle')
  58.  
  59. DO WHILE ~EOF('loghandle')
  60.     IF LEFT(inline,1) = '$' THEN
  61.         DO
  62.             PARSE VAR inline . date '-' month '-' year logtime direction ' # ' node ' # ' size .
  63.  
  64.             date=STRIP(date,'B')
  65.             year = '19' || year
  66.             nummonth = monthtonum(month)
  67.             logdate = year || nummonth || date
  68.  
  69.             IF Complete | (logdate >= StartDate & logdate <= StopDate) THEN
  70.                 DO
  71.                     IF sent.node = 0 & received.node = 0 THEN        /* Add him to the list */
  72.                         DO
  73.                             nodecounter = nodecounter + 1
  74.                             nodes.0 = nodecounter
  75.                             nodes.nodecounter = node
  76.                         END
  77.  
  78.                     IF direction = 'F->U:' THEN
  79.                         sent.node = sent.node + size
  80.                     ELSE
  81.                         received.node = received.node + size
  82.                 END
  83.         END
  84.  
  85.     inline = READLN('loghandle')
  86. END
  87.  
  88. CALL CLOSE('loghandle')
  89.  
  90. CALL nodesort 1,nodes.0                                        /* Sort nodes */
  91.  
  92. SAY 'Dear Sysop'
  93. SAY ''
  94. SAY 'Here are the results from your log-request. Generated' DATE()
  95. SAY ''
  96. IF Complete = 0 THEN
  97.     DO
  98.         DispStartDate = DATE('N',StartDate,'S')        /* For display in stats  */
  99.         DispStopDate = DATE('N',StopDate,'S')
  100.         SAY 'Covering the period from' DispStartDate 'to' DispStopDate
  101.         SAY ''
  102.     END
  103.  
  104. SAY '+-----------------+---------+---------+'
  105. SAY '| Node            | Kb sent | Kb rec. |'
  106. SAY '+-----------------+---------+---------+'
  107. DO i = 1 TO nodecounter
  108.     name = nodes.i
  109.     kbsent = sent.name / 1024
  110.     Remainder = kbsent // 1
  111.     kbsent = kbsent % 1
  112.     IF Remainder > 0.5 THEN kbsent = kbsent + 1
  113.  
  114.     kbreceived = received.name / 1024
  115.     Remainder = kbreceived // 1
  116.     kbreceived = kbreceived % 1
  117.     IF Remainder > 0.5 THEN kbreceived = kbreceived + 1
  118.  
  119.     SAY '|' LEFT(name,15) '|' RIGHT(kbsent,7) '|' RIGHT(kbreceived,7) '|'
  120.     SAY '+-----------------+---------+---------+'
  121. END
  122.  
  123. SIGNAL exit
  124.  
  125. syntax:
  126. say rc errortext(rc) 'in line' SIGL
  127. exit:
  128. EXIT
  129.  
  130. /***************************************/
  131. /* Sort-routines. QuickSort algoritm   */
  132. /***************************************/
  133. nodesort: PROCEDURE EXPOSE nodes.
  134. ARG Left,Right
  135. i = Left; j = Right
  136. m = (Left + Right) % 2
  137. tempm = nodes.m
  138. DO UNTIL (i > j)
  139.     DO WHILE (nodes.i < tempm & i < Right)
  140.         i = i + 1
  141.     END
  142.  
  143.     DO WHILE (nodes.j > tempm & j > Left)
  144.         j = j - 1
  145.     END
  146.     IF i <= j THEN
  147.         DO
  148.             Temp = nodes.i
  149.             nodes.i = nodes.j
  150.             nodes.j = Temp
  151.             i = i + 1
  152.             j = j - 1
  153.         END
  154. END
  155. IF Left < j  THEN CALL nodesort Left,j
  156. IF i < Right THEN CALL nodesort i,Right
  157. RETURN
  158.  
  159. monthtonum: PROCEDURE
  160. ARG month
  161. SELECT
  162.     WHEN month = 'JAN' THEN nummonth = '01'
  163.     WHEN month = 'FEB' THEN nummonth = '02'
  164.     WHEN month = 'MAR' THEN nummonth = '03'
  165.     WHEN month = 'APR' THEN nummonth = '04'
  166.     WHEN month = 'MAY' THEN nummonth = '05'
  167.     WHEN month = 'JUN' THEN nummonth = '06'
  168.     WHEN month = 'JUL' THEN nummonth = '07'
  169.     WHEN month = 'AUG' THEN nummonth = '08'
  170.     WHEN month = 'SEP' THEN nummonth = '09'
  171.     WHEN month = 'OCT' THEN nummonth = '10'
  172.     WHEN month = 'NOV' THEN nummonth = '11'
  173.     WHEN month = 'DEC' THEN nummonth = '12'
  174.     OTHERWISE nummonth = '00'
  175. END
  176.  
  177. RETURN(nummonth)
  178.